<?php

function markDir($dir,&$r)
{
    $fs = glob($dir.'/*');
    
    if(count($fs) == 0){
    	$r[] = $dir;
    }else{
    	foreach($fs as $f){
    		if(is_dir($f)){
    			markDir($f,$r);
    		}else{
    			$r[] = $f;
    		}
    	}
    }    
}
function mkdirs($dir, $mode = 0777)
{
    if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE;
    if (!mkdirs(dirname($dir), $mode)) return FALSE;
 
    return @mkdir($dir, $mode);
}


function copyDir($from,$to){
	$res = array();
	markDir($from,$res);
	
	foreach($res as $f){
		$nf = str_replace(dirname($from),$to,$f);
		if(is_dir($f)){
			mkdirs($nf);
		}else{
			mkdirs(dirname($nf));
			copy($f,$nf);
		}	
	}
}
?>